<?php

class admin_template_user_manager_edit extends admin_theme
{
    
	protected function head()
	{
	    $user = $this->get('user');
	    echo '<script type="text/javascript" language="javascript" src="apps/user/templates/manager/js/edit.js"></script>';
	    if(($user->id>0))
		{
		    echo '<script type="text/javascript" language="javascript">$(function(){hidePassword();});</script>';
		}

	}
    

	protected function center()
	{
		$user = $this->get('user');
		
		$ui_editor = bone::get_admin_ui('editor');
		$ui_editor->set_action('./?action=user.manager.edit_save');
		
		$field_username = array(
				'type'=>'text',
			    'name'=>'username',
			    'label'=>'用户名',
				'value'=>$user->username,
				'width'=>'200px',
				'validate'=>array(
					'required'=>true,
			        'min_length'=>3,
					'max_length'=>60
				),
				'message'=>array(
					'required'=>'请输入用户名',
					'min_length'=>'用户名最少需要输入{0}个字符',
					'max_length'=>'用户名最多可以输入{0}个字符'
				)
			);

		$field_email = array(
				'type'=>'text',
			    'name'=>'email',
			    'label'=>'邮箱',
				'value'=>$user->email,
				'width'=>'200px',
            	'validate'=>array(
					'required'=>true,
                    'email'=>true,
					'max_length'=>60
				),
				'message'=>array(
					'required'=>'请输入邮箱',
					'email'=>'邮箱格式错误',
					'max_length'=>'最多可以输入{0}个字符'
				)
			);
			
		$filed_password = array(
				'type'=>'password',
			    'name'=>'password',
			    'label'=>'设置密码',
				'width'=>'180px',
				'validate'=>array(
			        'min_length'=>5
				),
				'message'=>array(
				    'min_length'=>'密码最少需要输入{0}个字符'
				)
			);
			
		$filed_confirm_password = array(
				'type'=>'password',
			    'name'=>'password2',
			    'label'=>'确认密码',
				'width'=>'180px',
				'validate'=>array(
					'equal_to'=>'password'
				),
				'message'=>array(
					'equal_to'=>'两次输入的密码不一致'
				)
			);
			
	    if(($user->id==0))
		{
		    $field_username['validate']['remote'] = './?action=user.manager.check_username';
		    $field_username['message']['remote'] = '此用户名已被占用';
		    
		    $field_email['validate']['remote'] = './?action=user.manager.check_email';
		    $field_email['message']['remote'] = '此邮箱已被占用';

		    $filed_password['validate']['required'] = true;
		    $filed_password['message']['required'] = '请输入密码';
		    
		    $filed_confirm_password['validate']['required'] = true;
		    $filed_confirm_password['message']['required'] = '请确认密码';
		}
		else 
		{
		    $filed_password['label'] = '<input type="checkbox" id="change_password" onclick="javascript:changePassword(this.checked);">修改密码';
		}
		
		
		
		$ui_editor->set_fields(
			array(
				'type'=>'file',
			    'name'=>'avatar',
			    'label'=>'头像',
			    'html'=>'<img src="../'.$user->avatar.'" />'.($user->avatar=='apps/user/avatars/0.png'?'':(' <a href="javascript:;" onclick="javascript:deleteAvatar(this, '.$user->id.');" style="font-size:16px;">&times;</a>')).'<br /><input type="file" name="avatar" />'
			),
			$field_username,
            $field_email,
            array(
				'type'=>'text',
			    'name'=>'name',
			    'label'=>'名字',
				'value'=>$user->name,
				'width'=>'120px',
            	'validate'=>array(
					'max_length'=>60
				),
            	'message'=>array(
					'max_length'=>'名字最多可以输入{0}个字符'
				)
			),
			$filed_password,
			$filed_confirm_password,
			array(
				'type'=>'checkbox',
			    'name'=>'is_admin',
			    'label'=>'登陆后台权限',
			    'value'=>$user->is_admin,
				'options'=>array('1'=>'')
			),
			array(
				'type'=>'checkbox',
			    'name'=>'block',
			    'label'=>'屏蔽该用户',
			    'value'=>$user->block,
				'options'=>array('1'=>'')
			)			
		);
		
		$ui_editor->add_hidden('id', $user->id);
		$ui_editor->add_hidden('return', $this->get('return'));
		
		$ui_editor->set_reset('重设');
		$ui_editor->set_back('返回', base64_decode($this->get('return')));
		$ui_editor->display();

	}	

}
?>